import asyncio
from mqtt_client import MQTTClient
from px4.drone_controller import DroneController
from monitor.status_monitor import StatusMonitor
from utils.logger import logger

MQTT_BROKER = "127.0.0.1"
MQTT_PORT = 1883


async def main():
    loop = asyncio.get_event_loop()  # 获取主线程的事件循环

    drone_controller = DroneController()
    await drone_controller.connect()

    mqtt_client = MQTTClient(MQTT_BROKER, MQTT_PORT, drone_controller, loop)
    mqtt_client.connect()

    status_monitor = StatusMonitor(drone_controller.drone, mqtt_client)
    await status_monitor.start_monitoring()


if __name__ == "__main__":
    logger.info("启动无人机控制程序")
    asyncio.run(main())
